package com.hzhk.happyrent.ui.holder.rent;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hzhk.happyrent.Constants;
import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.rent.BaseBean;
import com.hzhk.happyrent.bean.rent.ProductListNewsBean;
import com.hzhk.happyrent.bean.rent.RentTopModel;
import com.hzhk.happyrent.network.API;
import com.hzhk.happyrent.network.HttpManager;
import com.hzhk.happyrent.network.MyStringResponse;
import com.hzhk.happyrent.ui.activity.rent.ProductDetailsActivity;
import com.hzhk.happyrent.ui.activity.rent.ProductListActivity;
import com.hzhk.happyrent.ui.adapter.rent.HomeNewsAdapter;
import com.hzhk.happyrent.ui.view.MyGridView;
import com.hzhk.happyrent.ui.view.listview.MaiTianListview;
import com.hzhk.happyrent.utils.ListUtils;
import com.tamic.novate.Throwable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class HomeNewsViewHolder{

    @BindView(R.id.home_more)
    TextView homeMore;
    @BindView(R.id.rent_type_function)
    MyGridView rentTypeFunction;
    @BindView(R.id.banner_img)
    ImageView bannerImg;


    HomeNewsAdapter homeNewsAdapter;
    private Context context;

    public HomeNewsViewHolder(View convertView, Context context) {
        this.context = context;
        ButterKnife.bind(this, convertView);
        initView();
    }
    public void setAction(BaseBean baseBean){
        ProductListNewsBean productListNewsBean = (ProductListNewsBean) baseBean;
        homeNewsAdapter.setList(productListNewsBean.getData().getGoods());
    }
    private void initView() {
        bannerImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, ProductDetailsActivity.class);
                intent.putExtra(Constants.GOODS_ID,"65");
                context.startActivity(intent);
            }
        });
        homeNewsAdapter=new HomeNewsAdapter(context);
        rentTypeFunction.setAdapter(homeNewsAdapter);
        rentTypeFunction.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent=new Intent(context, ProductDetailsActivity.class);
                intent.putExtra(Constants.GOODS_ID,((HomeNewsAdapter)adapterView.getAdapter()).getItem(i).getId());
                context.startActivity(intent);
            }
        });
    }
    @OnClick({R.id.home_more})
    public void onViewClicked(View view) {
        Intent intent=new Intent(context, ProductListActivity.class);
        intent.putExtra(Constants.ACTION,Constants.ACTION2);
        context.startActivity(intent);
    }
}